#ifndef KERNEL_MEMORY_MEMORY_H
#define KERNEL_MEMORY_MEMORY_H

#include <Mint/Types.h>
#include "Memory/PhysicalHeap.h"

#if TRACE_MEMORY
#define MEMORY_TRACE(x ...) TRACE("Memory: " x)
#else
#define MEMORY_TRACE(x ...)
#endif

#if TRACE_MEMORY && TRACE_MEMORY_DETAILED
#define MEMORY_TRACE_DETAILED(x ...) TRACE("Memory: " x)
#else
#define MEMORY_TRACE_DETAILED(x ...)
#endif

#define MEMORY_USE_WALLS 1
#define MEMORY_PAGE_SIZE				    ( (Size)4096U )
#define MEMORY_PAGE_MASK				    ( MEMORY_PAGE_SIZE - (Size)1U )
#define MEMORY_PAGE_ALIGN(address)		    ( (Size)address & ~MEMORY_PAGE_MASK )
#define MEMORY_IS_PAGE_ALIGNED(address)     ( ( (Size)address & MEMORY_PAGE_MASK ) == 0 )

inline void * operator new ( Size size )
{
	return PhysicalHeap->Allocate( size );
}

inline void * operator new ( Size size, void * location ) throw()
{
	return location;
}

inline void * operator new[] ( Size size )
{
	return PhysicalHeap->Allocate( size );
}

inline void * operator new[] ( Size size, void * location ) throw()
{
	return location;
}

inline void operator delete ( void * memory )
{
	PhysicalHeap->Free( memory );
}

inline void operator delete ( void * memory, void * location ) throw()
{
}

#endif // KERNEL_MEMORY_MEMORY_H
